<template>
  <div class="tab-bar-item" @click="itemclick">
    <!--    具名插槽-->
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  //获取动态路径
  props:{
    path:String,
    activeColor:{
      type:String,
      default:'red'
    },
    data(){
      return{

      }
    }
  },
  computed:{
    isActive(){
      return this.$route.path.indexOf(this.path) !== -1
    },
    activeStyle(){
      return this.isActive?{color:this.activeColor}:{}
    }
  },
  methods:{
    itemclick(){
      this.$router.replace(this.path).catch(err => err)
    }
  }
}
</script>

<style scoped>
.tab-bar-item{
  /* 实现均等分 */
  flex: 1;
  /* 居中 */
  text-align: center;
  /* tabber的高度一般为49 */
  height: 49px;

  font-size: 14px;
}

.tab-bar-item img{
  width: 20px;
  height: 20px;
  /* 调整图片和文字的间距 */
  margin-top: 3px;
  margin-bottom: 2px;
  vertical-align: middle;
}
</style>